home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / html / vendors / charybda / software / InstallIt2.csh < prev    next >
Linux/UNIX/POSIX Shell Script  |  1997-07-27  |  12KB  |  411 lines

  1. #!/bin/csh -f
  2.  
  3. #   This is an example installation script for HotMix.
  4. #
  5. #   The bulk of the code in this script is aimed at determining the
  6. #   INST_PATH -- the place to install the software (this isn't as
  7. #   easy as it might initially seem!).  The default is to copy to an
  8. #   installation directory in /usr/tmp.  If /usr/tmp doesn't exist,
  9. #   there is not enough disk space, or the user prefers another directory,
  10. #   the script will ask for another directory name.  In this case,
  11. #   the script will read the desired directory name, check its validity,
  12. #   check the available disk space, and if everything is OK, will then
  13. #   do the installation.
  14. #
  15. #   To customize the script, you will need to change these 4 parameters:
  16. #
  17. #       MYAPP = name of the application
  18. #
  19. #       INST_DIR = name of the installation directory
  20. #                  (this is the directory name, not the full path name)
  21. #       CD_PATH = directory path of the location of the software
  22. #                 on the HotMix CD-ROM (it must begin with "$HOTMIXDIR",
  23. #                 which is the mount point for the CD-ROM drive).
  24. #       KBYTES_REQ = required size of the full installation (in Kbytes).
  25. #
  26. #   In this simple example, the installation just involves copying
  27. #   the software to the hard disk, and then launching the application.
  28. #   In other cases, the installation will probably be more complicated,
  29. #   so you'll need to change the code at the end of the script as well.
  30. #   The rest of the script should not require modification.
  31. #
  32. #   All of the InstallIt and RemoveIt scripts should reside in the
  33. #   $CD_PATH directory.
  34. #
  35. #                                                 
  36. #
  37. #                                                 
  38.  
  39.  
  40. set MYAPP=diver
  41. set INST_DIR=charybda
  42. set KBYTES_REQ=1000
  43.  
  44. #
  45. #  Test to see if on the new Indy filesystem or old one.
  46. #
  47.  
  48. set TEST_NEW=`df -k /usr | /usr/bin/awk '{print $7}'`
  49.  
  50. if ( "$TEST_NEW" == "Mounted /" ) then
  51.    set FILE_STRUCTURE=new
  52.  
  53. else
  54.    set FILE_STRUCTURE=old
  55. endif
  56.  
  57.  
  58. #
  59. #  Determine the INST_PATH name.
  60. #
  61. #  First try /usr/tmp;  then if necessary, ask for another directory.
  62. #
  63.  
  64. @ MBYTES_REQ = ($KBYTES_REQ) / 1000
  65.  
  66. if ( $FILE_STRUCTURE == "new" ) then
  67.    set KBYTES_AVAIL=`df -k / | /bin/grep / | /usr/bin/awk '{print $5}'`
  68. else
  69.    set KBYTES_AVAIL=`df -k /usr | /bin/grep /usr | /usr/bin/awk '{print $5}'`
  70. endif
  71.  
  72. if ( -x /usr/tmp/charybda/diver ) then
  73.     echo " "
  74.     echo "It seems the demo is already installed.  Would you like to launch it? (y/n)?  \c"
  75.     set ans3=($<)
  76.     if ( $ans3 == 'y' ) then
  77.         echo "Launching Charybda Diver ...."
  78.  
  79. if !($?home) then
  80.         if !($?user) then
  81.                 set usermatch = "^[^:]*:[^:]*:`id -u`:"
  82.                 echo "user not set... using $usermatch"
  83.         else
  84.                 set usermatch = "^$user:"
  85.         endif
  86.  
  87.         set newhome = `grep "$usermatch" /etc/passwd | head -1 | cut -d: -f6`
  88.         echo "home directory not set... setting to $newhome"
  89.         set home = "$newhome"
  90. endif
  91.  
  92.         jot -fv $TMPFILEDIR/charybda/diver_demo_instr &
  93.  
  94.         $TMPFILEDIR/charybda/diver
  95.         exit
  96.     else
  97.         echo " "
  98.         echo "Would you like to continue with another install? (y/n)?  \c"
  99.                 set ans3=($<)
  100.                 if ( $ans3 != 'y' ) then
  101.                     echo " "
  102.                     echo "... Bye."
  103.                     sleep 3
  104.                     exit
  105.         else
  106.             echo " "
  107.             echo "Would you like to remove this software before contining? (y/n)?  \c"
  108.             set ans3=($<)
  109.             if ( $ans3 == 'y' ) then
  110.                 if ( -w /usr/tmp/charybda ) then
  111.                     echo " "
  112.                     echo "Removing /usr/tmp/charybda "
  113.                     rm -rf /usr/tmp/charybda
  114.                 else
  115.                     echo " "
  116.                     echo "Don't have permission! "
  117.                     echo "Continuing with install..."
  118.                 endif
  119.             endif
  120.                 endif
  121.     endif
  122. endif
  123.  
  124. if ( -w /usr/tmp ) then
  125.  
  126.     if ( $KBYTES_AVAIL > $KBYTES_REQ ) then
  127.  
  128.         set INST_PATH=/usr/tmp/$INST_DIR
  129.  
  130.         echo " "
  131.         echo "This demo requires $MBYTES_REQ Mbytes of disk space."
  132.         echo " "
  133.         echo "It will be installed in a directory named $INST_PATH"
  134.         echo "Is this OK (y/n)?  \c"
  135.         set ans=($<)
  136.         if ( $ans != 'y' ) then
  137.             echo " "
  138.             echo "Do you want to install in another directory (y/n)?  \c"
  139.             set ans2=($<)
  140.             if ( $ans2 != 'y' ) then
  141.                 echo " "
  142.                 echo "... Bye."
  143.                 sleep 3
  144.                 exit
  145.             else
  146.                 set INST_PATH=none
  147.             endif
  148.         else
  149.             if ( -d $INST_PATH ) then
  150.                 echo " "
  151.                 echo "It seems the demo is already installed.  Continue anyway (y/n)?  \c"
  152.                 set ans3=($<)
  153.                 if ( $ans3 != 'y' ) then
  154.                     echo " "
  155.                     echo "... Bye."
  156.                     sleep 3
  157.                     exit
  158.                 endif
  159.                 rm -rf $INST_PATH
  160.             endif
  161.         endif
  162.     else
  163.         set INST_PATH=none
  164.     endif
  165. else
  166.     set INST_PATH=none
  167. endif
  168.  
  169. if ( $INST_PATH == "none" ) then
  170.  
  171. #   Read name of installation directory.
  172.  
  173.     echo " "
  174.     echo "This demo requires $MBYTES_REQ Mbytes of disk space."
  175.  
  176.     LOOP1:
  177.  
  178.     unset INSTDIR_FILESYS
  179.  
  180.     echo " "
  181.     echo "Enter the full path name of an existing directory"
  182.     echo "in which to copy the software (or enter 'q' to quit):  \c"
  183.     set ans=($<)
  184.  
  185. #   Check validity of the path name.  If it contains only a "/",
  186. #   this will cause a divide by zero, and fail.
  187.     set TEST1=`echo $ans | cut -f2 -d"/"`
  188.     if ( ! $#TEST1 ) then
  189.             echo " "
  190.             echo "You cannot use directory /.  Please try again."
  191.             goto LOOP1
  192.     endif
  193.  
  194.     if ( $ans == 'q' ) then
  195.         echo " "
  196.         echo "... Bye."
  197.         sleep 3
  198.         exit
  199.     else if ( $#ans == 0 ) then
  200.         echo " "
  201.         echo "Input error.  Please try again."
  202.         goto LOOP1
  203.     else
  204.  
  205. #       Check validity of the path name again.  It must begin with "/".
  206.         set TEST2=`echo $ans | cut -f2 -d"/" -s`
  207.         if ( ! $#TEST2 ) then
  208.                 echo " "
  209.                 echo "The pathname must begin with /.  Please try again."
  210.                 goto LOOP1
  211.         endif
  212.  
  213.         if ( -d $ans ) then
  214.  
  215.             echo " "
  216.             echo "A $INST_DIR directory will be created in $ans."
  217.             echo "Is this OK (y/n)?:  \c"
  218.             set ans2=($<)
  219.             if ( $ans2 != 'y' ) goto LOOP1
  220.  
  221. #           Determine the space available for the filesystem
  222. #           containing the requested directory.
  223. #
  224.  
  225. #                       Check to see if the directory is actually a link or an
  226. #                       nfs mount and do appropriate checks.
  227.  
  228.                         if ( -l $ans ) then
  229.                                 cd $ans
  230.                                 set CDIR=`pwd`
  231.                                 set KBYTES_AVAIL=`df -k $CDIR | /usr/bin/awk '{print $5}'`
  232.                         endif
  233.  
  234.                         touch $ans/hmtest
  235.                         if ( ! -r $ans/hmtest ) then
  236.  
  237.                                 echo "Can not write to $ans, please choose another directory."
  238.                                 goto LOOP1
  239.                         endif
  240.             /bin/rm -f $ans/hmtest
  241.  
  242.  
  243.  
  244. #           First, find all the mounted filesystems.
  245.             set FILESYSTEMS=`df -k | awk '{print $7}' | grep /`
  246.  
  247. #           Now, beginning with the full path name of the
  248. #           requested directory, start stripping off the trailing
  249. #           subdirectory names, and compare this to the existing
  250. #           file system names.  If these match exactly, then we've
  251. #           found the right file system.
  252.  
  253.             set TEST3=`echo $ans | cut -f3 -d"/"`
  254.             if ( ! $#TEST3 ) then
  255.                 set PATH=$ans
  256.             else
  257.                 set PATH=`dirname $ans`
  258.             endif
  259.             LOOP2:
  260.                 foreach FILESYSTEM ($FILESYSTEMS)
  261.  
  262. #                   Don't do the test if $FILESYSTEM == "/"
  263.                     set TEST4=`echo $FILESYSTEM | cut -f2 -d"/"`
  264.                     if ( $#TEST4 != 0 ) then
  265.  
  266.                         if ( $PATH == $FILESYSTEM ) then
  267.                             set INSTDIR_FILESYS=$PATH
  268.                         endif
  269.                     endif
  270.                 end
  271.                 set PATH=`dirname $PATH`
  272.  
  273. #           Continue looping until we've stripped the pathname
  274. #           down to only "/", or until we find the file system.
  275.  
  276.             set LOOPTEST=`echo $PATH | cut -f2 -d"/"`
  277.             if (( $#LOOPTEST != 0 ) && ( ! $?INSTDIR_FILESYS )) goto LOOP2
  278.  
  279.             if ( $?INSTDIR_FILESYS ) then
  280.  
  281. #               Determine the available space
  282.  
  283.                 set KBYTES_AVAIL=`df -k $INSTDIR_FILESYS | /bin/grep $INSTDIR_FILESYS | /usr/bin/awk '{print $5}'`
  284.  
  285.             else
  286.                 if ( $FILE_STRUCTURE == "new" ) then
  287.                   set KBYTES_AVAIL=`df -k / | /bin/grep / | /usr/bin/awk '{print $5}'`
  288.                 else
  289.                 echo " "
  290.                 echo "  ERROR:  Can't determine the amount of available disk"
  291.                 echo "          space for the directory you requested."
  292.                 echo " "
  293.                 echo "          Continue anyway (y/n)?  \c"
  294.                 set ans3=($<)
  295.                 if ( $ans3 == 'y' ) then
  296.                     @ KBYTES_AVAIL = ($KBYTES_REQ) + 1
  297.                 else
  298.                     echo " "
  299.                     echo "... Bye."
  300.                     sleep 3
  301.                     exit
  302.                 endif
  303.             endif
  304.        endif
  305.  
  306.             if ( $KBYTES_AVAIL > $KBYTES_REQ ) then
  307.                 if ( -w $ans ) then
  308.  
  309. #                   Success!!!
  310.  
  311.                     set INST_PATH=$ans/$INST_DIR
  312.                     echo " "
  313.                 else
  314.                     echo " "
  315.  
  316.                     echo "Can't write to directory $ans."
  317.                     echo "Please try again."
  318.                     goto LOOP1
  319.                 endif
  320.             else
  321.                 echo " "
  322.                 echo "Not enough space available."
  323.                 echo "Please try again."
  324.                 goto LOOP1
  325.             endif
  326.         else
  327.             echo " "
  328.             echo "Can't find directory $ans."
  329.             goto LOOP1
  330.         endif
  331.     endif
  332.  
  333.     # Check installation directory.
  334.     if ( -d $INST_PATH ) then
  335.         echo " "
  336.         echo "It seems the demo is already installed.  Continue anyway (y/n)?  \c"
  337.         set ans3=($<)
  338.         if ( $ans3 != 'y' ) then
  339.             echo " "
  340.             echo "... Bye."
  341.             sleep 3
  342.             exit
  343.         endif
  344.  
  345.         rm -rf $INST_PATH
  346.     endif
  347. endif
  348.  
  349. #  Store INST_PATH in a file so it can be communicated to the RemoveIt script.
  350. #
  351. #  First, try to put it in /usr/tmp.  If we can't, then put it in /tmp
  352. #  and in the user's home directory.  If put in /tmp, the file will
  353. #  disappear if the machine is rebooted.  If put in the user's home
  354. #  directory, we won't be able to find it if the user trying to remove
  355. #  the software is not the same as the user who installed it.  Either
  356. #  case isn't very good, but it's the best we can do if we can't write
  357. #  to /usr/tmp.
  358.  
  359. #/bin/rm -f /usr/tmp/HOTMIXPATH_$INST_DIR > /dev/null
  360. #/bin/rm -f /tmp/HOTMIXPATH_$INST_DIR > /dev/null
  361.  
  362. #/bin/rm -f ~/HOTMIXPATH_$INST_DIR > /dev/null
  363.  
  364. #if ( -w /usr/tmp ) then
  365. #    echo "setenv INST_PATH $INST_PATH" > /usr/tmp/HOTMIXPATH_$INST_DIR
  366. #    /bin/chmod 666 /usr/tmp/HOTMIXPATH_$INST_DIR
  367. #else
  368. #    echo "setenv INST_PATH $INST_PATH" > /tmp/HOTMIXPATH_$INST_DIR
  369. #    /bin/chmod 666 /tmp/HOTMIXPATH_$INST_DIR
  370.  
  371. #    echo "setenv INST_PATH $INST_PATH" > ~/HOTMIXPATH_$INST_DIR
  372. #    /bin/chmod 666 ~/HOTMIXPATH_$INST_DIR
  373. #endif
  374.  
  375. #
  376. #-----------------------------------------------------------------------
  377. #
  378. #  Now that we've finally determined INST_PATH, do the installation.
  379. #  In this case, just copy the software and execute the application.
  380.  
  381. echo " "
  382. echo "Installing Diver Demo.  Please wait..."
  383.      mkdir -p $INST_PATH
  384. #     cd $INST_PATH
  385.     cp -r $CD_PATH/charybda/* $INST_PATH
  386. sleep 10
  387. echo " "
  388. echo "Done."
  389. echo " "
  390. echo "To run the demo:" 
  391. echo "Move to the $INST_PATH directory"
  392. echo "and execute $MYAPP."
  393. echo " "
  394. echo " "
  395. echo "You should also view the demo instructions"
  396. echo "in the $INST_PATH directory. "
  397. echo " "
  398. echo "Do you want to run the demo now (y/n)?  \c"
  399. set ans=($<)
  400. if ( $ans == 'y' ) then
  401.     cd $INST_PATH
  402.     ./diver &
  403.     jot -fv ./diver_demo_instr
  404. else
  405.     echo "... Bye."
  406.     sleep 3
  407. endif
  408. echo "Press Enter to exit this window...  \c"
  409. set a = $<
  410.  
  411.